﻿#include "CPdfRptBase.h"
#include "CGlobal.h"
#include "CPdfRptRestAiOperBase.h"

CPdfRptBase::CPdfRptBase()
{
	//初始工具类
	m_pPdfRptTool = new CPdfRptTool();
	m_pPdfRptTool->defineMinCell(140.0, 30.0);//定义最小单元格

	m_pPdfRptRestAiOperBase = new CPdfRptRestAiOperBase(m_pPdfRptTool);
}

CPdfRptBase::~CPdfRptBase()
{
	if (m_pPdfRptTool)
	{
		delete m_pPdfRptTool;
		m_pPdfRptTool = nullptr;
	}
	if (m_pPdfRptRestAiOperBase)
	{
		delete m_pPdfRptRestAiOperBase;
		m_pPdfRptRestAiOperBase = nullptr;
	}
}

bool CPdfRptBase::drawRptName(QString sRptName, EPdfRptComPosition ePosition, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	if (m_pPdfRptTool == nullptr)
	{
		return false;
	}

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev40Bold, enPdfRptPenBlackBold);//设置字体和画笔等级
	m_pPdfRptTool->drawSingleText(ePosition, sRptName, painter, printer, sErrMsg);

	return true;
}

bool CPdfRptBase::optRestAiPdfRptInfo(CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	if (m_pPdfRptRestAiOperBase == nullptr)
	{
		return false;
	}

	double dDrawStartRow = 0.0;//绘制起始行
	double dDrawStartCol = 0.0;//绘制起始列

	// 创建一个QPrinter对象
	QPrinter printer(QPrinter::PrinterResolution);
	printer.setOutputFormat(QPrinter::PdfFormat);
	printer.setOutputFileName(dataInfo.extraAiDataInfo.m_sOutputPdfFolder);// 设置输出路径
	printer.setPageSize(QPageSize(QPageSize::A4));// 设置页面大小为A4

	// 创建一个QPainter对象，并将其与QPrinter关联起来
	QPainter painter;
	if (!painter.begin(&printer))
	{
		sErrMsg = A2T("QPainter begin 失败");
		return false;
	}

	//使用公共-->绘制报告名称
	drawRptName(A2T("      AI检测报告"), enRestAiPdfRptPosName, painter, printer, sErrMsg);

	//使用AI检测操作类-->绘制综述表格
	dDrawStartRow = 6;//开始行
	dDrawStartCol = 0;//开始列
	m_pPdfRptRestAiOperBase->drawRestAiOverviewForm(dDrawStartRow, dDrawStartCol, dataInfo, painter, printer, sErrMsg);

	//使用Ai检测操作类-->绘制所有其他Ai检测报警
	m_pPdfRptRestAiOperBase->drawRestAiAllAlmDes(dDrawStartRow, dDrawStartCol, dataInfo, painter, printer, sErrMsg);

	return true;
}
